import request from '@/utils/request.js'

// 获取文章列表 
// orderType 0:热门（默认） 1:最新发布
export const getForumArticleListService = (formData) => {
  return request.get('/user/forumArticle/getForumArticleList',
    { params: formData }
  )
}

// 获取文章详情
export const getForumArticleDetailService = (formData) => {
  return request.get('/user/forumArticle/getForumArticleDetail',
    { params: formData }
  )
}

// 根据文章id获取文章详情以及附件（文章修改用，回显）
export const getForumArticleDetailForUpdate = (formData) => {
  return request.get('/user/forumArticle/getForumArticleDetailForUpdate',
    { params: formData }
  )
}

// 文章内容上传图片
export const uploadArticleContentImgService = (formData) => {
  return request.post('/user/forumArticle/uploadArticleContentImg', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
}

// 文章搜索
export const searchArticleService = (formData) => {
  return request.get('/user/forumArticle/searchArticle',
    { params: formData }
  )
}

// 类似文章推荐
export const getRelativeArticleService = (formData) => {
  return request.get('/user/forumArticle/getRelativeForumArticle',
    { params: formData }
  )
}

// 文章点赞
export const doArticleLikeService = (formData) => {
  return request.post('/user/forumArticle/doArticleLike', formData)
}

// 下载附件
export const attachmentDownloadService = (formData) => {
  return request.get('/user/forumArticle/downloadAttachment',
    {
      params: formData,
      responseType: 'blob'
    }
  )
}

// 发表文章
export const postArticleService = (formData) => {
  return request.post('/user/forumArticle/postArticle', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
}

// 修改文章
export const updateArticleService = (formData) => {
  return request.post('/user/forumArticle/updateForumArticle', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
}

// 根据用户ID获取文章列表
export const getForumArticleListByUserIdService = (formData) => {
  return request.get('/user/forumArticle/getForumArticleListByUserId',
    { params: formData }
  )
}

// 根据文章ID删除文章
export const deleteForumArticleByArticleIdService = (formData) => {
  return request.delete('/user/forumArticle/deleteForumArticleByArticleId',
    { params: formData }
  )
}

// 文章搜索
export const searchForumArticleService = (formData) => {
  return request.get('/user/forumArticle/searchForumArticle',
    {
      params: {
        ...formData,
        _t: Date.now()  // 添加时间戳防止缓存
      },
      headers: {  // 请求头（禁用缓存）
        'Cache-Control': 'no-cache',
        'Pragma': 'no-cache',
        'Expires': '0'
      }
    }
  )
}

// 获取热点文章
export const getHotArticleService = (formData) => {
  return request.get('/user/forumArticle/getHotArticle')
}